package com.blockmeta.bbs.immodule.widget.msgview;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.Params;
import com.blockmeta.bbs.immodule.bean.databean.CardContentBean;
import com.blockmeta.bbs.immodule.bean.databean.F10ContentBean;
import com.blockmeta.bbs.immodule.dao.ChatMessage;
import com.chad.library.adapter.base.BaseViewHolder;

public class CardMsgView<T extends ChatMessage> extends MsgView<T>{

    public CardMsgView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.im_chat_card;
    }

    @Override
    public void convert(BaseViewHolder helper, T item, T lastItem) {
        super.convert(helper, item, lastItem);
        super.bindCommonControl(helper, item, lastItem);

        CardContentBean contentBean = getContentBean(item, CardContentBean.class);
        String deepLink = "";
        String linkText = "";
        if(contentBean.getCard_type() == Params.USER_PERSON){
            deepLink = TextUtils.isEmpty(contentBean.getUrl())
                    ? String.format("blockmeta://im/user?id=%s", contentBean.getId()) : contentBean.getUrl();
            linkText = "分享用户";
        }else {
            deepLink = TextUtils.isEmpty(contentBean.getUrl())
                    ? String.format("blockmeta://im/chatgroup_detail?id=%s", contentBean.getId()) : contentBean.getUrl();
            linkText = "分享圈子";
        }
        //发送消息！
        if (item.getType() == ChatMessage.TYPE_SEND) {
            ImageView icon = helper.getView(R.id.right_img_icon);
            LoadPicUtil.loadWithPicasso(icon, contentBean.getImg());
            helper.setText(R.id.right_title, contentBean.getName());
            helper.setText(R.id.right_desc, contentBean.getDesc());
            helper.setText(R.id.right_link, linkText);
            View contentLayout = helper.getView(R.id.chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.chat_item_layout_content);
        } else {
            //接收消息
            ImageView icon = helper.getView(R.id.left_img_icon);
            LoadPicUtil.loadWithPicasso(icon, contentBean.getImg());
            helper.setText(R.id.left_title, contentBean.getName());
            helper.setText(R.id.left_desc, contentBean.getDesc());
            helper.setText(R.id.left_link, linkText);
            View contentLayout = helper.getView(R.id.left_chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.left_chat_item_layout_content);
        }

    }

}
